package com.kajespero.model;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.NotPersistent;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;
import com.kajespero.model.annotation.MappedValue;
import com.kajespero.model.annotation.enums.RelationType;
import com.kajespero.vo.PageVO;
import com.kajespero.vo.TemplateVO;
import com.kajespero.webapp.editor.annotation.PropertyEditorSupport;
import com.kajespero.webapp.editor.impl.SummaryPropertyEditorSupport;
import com.kajespero.webapp.editor.impl.TemplatePropertyEditorSupport;
import com.kajespero.webapp.validator.annotation.Validator;
import com.kajespero.webapp.validator.impl.PageValidator;

@Validator(clazz=PageValidator.class)
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class PageBean extends IdentifierVOBean<Long> implements PageVO{

	/**
	 * 
	 */
	private static final long serialVersionUID = -808631340420984730L;
	
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;
	
	@Persistent
	private Long id;
	
	@NotPersistent
	@PropertyEditorSupport(editor=SummaryPropertyEditorSupport.class, fieldName="summary", attributeName="id", required=true)
	@MappedValue(type=SummaryBean.class, relationType=RelationType.MANY_TO_ONE, mappedBy="summaryId")
	private SummaryBean summary;
	
	@Persistent
	private Key summaryId;
	
	@Persistent
	private String title;
	
	@NotPersistent
	@PropertyEditorSupport(editor=TemplatePropertyEditorSupport.class, fieldName="template", attributeName="id", required=true)
	@MappedValue(type=TemplateBean.class, relationType=RelationType.MANY_TO_ONE, mappedBy="templateId")
	private TemplateBean template;
	
	@Persistent
	private Key templateId;

	@Override
	public Long getId() {
		return this.id;
	}

	@Override
	public SummaryBean getSummary() {
		return this.summary;
	}

	@Override
	public String getTitle() {
		return this.title;
	}

	@Override
	public TemplateVO getTemplate() {
		return this.template;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setSummary(SummaryBean summary) {
		this.summary = summary;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void setTemplate(TemplateBean template) {
		this.template = template;
	}

	public Key getKey() {
		return key;
	}

	public void setKey(Key key) {
		this.key = key;
	}

	public Key getSummaryId() {
		return summaryId;
	}

	public void setSummaryId(Key summaryId) {
		this.summaryId = summaryId;
	}

	public Key getTemplateId() {
		return templateId;
	}

	public void setTemplateId(Key templateId) {
		this.templateId = templateId;
	}

}
